home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlib.zip / STRNCMP.C < prev    next >
Text File  |  1993-01-04  |  640b  |  25 lines

  1.  
  2. /*  File   : strncmp.c
  3.     Author : Richard A. O'Keefe.
  4.     Updated: 10 April 1984
  5.     Defines: strncmp()
  6.  
  7.     strncmp(s, t, n) compares the first n characters of s and t.
  8.     If they are the same in the first n characters it returns 0,
  9.     otherwise it returns the same value as strcmp(s, t) would.
  10. */
  11.  
  12. #include "strings.h"
  13.  
  14. int strncmp(s, t, n)
  15.     register char *s, *t;
  16.     register int n;
  17.     {
  18.         while (--n >= 0) {
  19.             if (*s != *t++) return s[0]-t[-1];
  20.             if (!*s++) return 0;
  21.         }
  22.         return 0;
  23.      }
  24.  
  25.